//单双击事件处理
import config from "@/config.js"

function sout(e) {
	console.log(e)
}
const audioSrc = config.baseUrl + '/audio/getAudioStream/';
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.src = '';
innerAudioContext.onError((e) => {
	console.log(e)
})

let touchNum = 0
export function click(fn, src) {
	const user = uni.getStorageSync("userData")
	const isYuyin = user.isYuyin
	console.log(isYuyin)
	if (isYuyin == 0) {
		fn()
		return
	}
	touchNum++
	setTimeout(() => {
		if (touchNum == 1) {
			console.log("单击")
			if (src != undefined) {
				if (src.endsWith('.mp3')) {
					innerAudioContext.src = src
				} else {
					innerAudioContext.src = audioSrc + src
				}
				innerAudioContext.play()
			}
			console.log(src)
		} else if (touchNum >= 2) {
			console.log("双击")
			fn()
			innerAudioContext.stop()
		}
		touchNum = 0
		return
	}, 250)
}